﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace mpsalary
{
    public partial class Report : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string a = ddlistYear.SelectedValue;
            //string b = ddlSchool.SelectedValue;//done by me
            //string c = ddlCourseGroup.SelectedValue; //done by me
            //Label1.Text = a;

            string dataString = "Data Source=localhost;Initial Catalog=PGSPORTAL;Integrated Security=True"; //Data Source must change because of different computer names! //Janee\\sqlexpress
            SqlConnection sqlConnection = new SqlConnection(dataString);
            sqlConnection.Open();
            SqlCommand sqlCommand;

            if (tbxCourseSearch.Text != "") //if the textbox is not empty
            {
                sqlCommand = new SqlCommand("select * from [Wages] WHERE Year = " + ddlistYear.SelectedValue + " AND Course LIKE '%" + tbxCourseSearch.Text + "%'AND PolyConducting LIKE '%" + ddlSchool.SelectedValue + "%'");
                
            }
            else
            {
                sqlCommand = new SqlCommand("select * from [Wages] WHERE Year = " + ddlistYear.SelectedValue + " AND Course LIKE '%" + ddlCourseGroup.SelectedValue + "%'AND PolyConducting LIKE '%" + ddlSchool.SelectedValue + "%'");
            }
           
           // sqlCommand = null;
            sqlCommand.Connection = sqlConnection;

            //SqlCommand sqlCommand = new SqlCommand("select * from [Wages] WHERE PolyConducting = '" + ddlSchool.SelectedValue + "'AND Course = '" + ddlCourseGroup.SelectedValue + "'"); //database error
            //sqlCommand.CommandText = "select * from [Wages] WHERE PolyConducting = '" + ddlSchool.SelectedValue + "'AND Course = '" + ddlCourseGroup.SelectedValue;
            //sqlCommand.CommandText = "select * from [Wages] WHERE Year = 2010 AND Course like '%__________%'";
            //("select * from [Wages] WHERE Year = " + ddlYear.SelectedValue + " AND Course LIKE '%" + ddlCourseGroup.SelectedValue + "%'")
            

            SqlDataReader dr = sqlCommand.ExecuteReader();
            /*while (dr.Read()) //while loop is also done by me
            {
                ddlistYear.SelectedValue = dr["Year"].ToString();
                ddlSchool.SelectedValue = dr["School"].ToString();
                ddlCourseGroup.SelectedValue = dr["Course"].ToString();
            }*/

            GridView1.DataSource = dr; //changed variable name from reader to dr
            GridView1.DataBind();
            lblReturnNoResults.Visible = false;

            if (GridView1.Rows.Count == 0)
            {
                GridView1.Visible = false;
                lblReturnNoResults.Visible = true;
                lblReturnNoResults.Text="Your search returned no results.";
            }
            else
            GridView1.Visible = true; //tried to make the gridview visible but failed.

            
            
        }


        protected void imagebtnHome_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("homePage.aspx");
        }

        protected void ddlSearchBy_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void ddlistYear_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        //protected void ddlSchool_SelectedIndexChanged(object sender, EventArgs e)
        //{

        //}

        protected void ddlCourseGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            
            ddlistYear.ClearSelection();
            ddlSchool.ClearSelection();
            ddlCourseGroup.ClearSelection();
            tbxCourseSearch.Text = "";
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Text = "Year";
                e.Row.Cells[1].Text = "Course";
                e.Row.Cells[2].Text = "Schools";
                e.Row.Cells[3].Text = "Employment Number of Fresh Graduates";
                e.Row.Cells[4].Text = "Employment Rate of Fresh Graduates";
                e.Row.Cells[5].Text = "Monthly Mean of Fresh Graduates";
                e.Row.Cells[6].Text = "Monthly Median of Fresh Graduates";
                e.Row.Cells[7].Text = "Employment Number of Post Graduates";
                e.Row.Cells[8].Text = "Employment Rate of Post Graduates";
                e.Row.Cells[9].Text = "Monthly Mean of Post Graduates";
                e.Row.Cells[10].Text = "Monthly Median of Post Graduates";
                e.Row.Cells[11].Text = "Industrial Area";
                
            }
        }

    }
}